﻿// 功能：控件事件
// 描述：
// 作者：温伟鹏
// 日期：2010/5/18 17:10:46

using System;
using System.Drawing;
using MeizuSDK.Drawing;

namespace MeizuSDK.Presentation
{
    #region 公共事件
    /// <summary>
    /// 当Control的Parent属性被改变后触发此事件
    /// </summary>
    /// <param name="sender">引发此事件的控件</param>
    /// <param name="e">事件参数</param>
    public delegate void ParentChangedEventHandler(object sender, ParentChangedEventArgs e);
    /// <summary>
    /// ParentChanged事件参数
    /// </summary>
    public class ParentChangedEventArgs : EventArgs
    {
        /// <summary>
        /// 获取改变前的控件父容器
        /// </summary>
        public object PreviousParent
        {
            get;
            private set;
        }
        /// <summary>
        /// 构造ParentChanged事件参数
        /// </summary>
        /// <param name="prevParent"></param>
        public ParentChangedEventArgs(object prevParent)
        {
            this.PreviousParent = prevParent;
        }
    }
    /// <summary>
    /// 当控件需要重绘时引发此事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    public delegate void PaintEventHandler(object sender, PaintEventArgs e);
    /// <summary>
    /// Paint事件参数
    /// </summary>
    public class PaintEventArgs : EventArgs
    {
        private Graphics g;
        private Rectangle winRect;
        private Rectangle updateRect;
        /// <summary>
        /// 获取控件绘图图面
        /// </summary>
        public Graphics Graphics
        {
            get
            {
                return g;
            }
        }
        /// <summary>
        /// 获取控件所在区域（如果是窗口触发事件，则此属性为空）
        /// </summary>
        public Rectangle ClientRectangle
        {
            get
            {
                return this.winRect;
            }
        }
        /// <summary>
        /// 获取待更新的矩形区域
        /// </summary>
        public Rectangle UpdateRectangle
        {
            get
            {
                return this.updateRect;
            }
        }

        public PaintEventArgs(Graphics g, Rectangle rectWin, Rectangle rectUpdate)
        {
            this.g = g;
            this.winRect = rectWin;
            this.updateRect = rectUpdate;
        }
    }
    /// <summary>
    /// 鼠标事件委托
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    public delegate void MouseEventHandler(object sender, MouseEventArgs e);
    /// <summary>
    /// 鼠标事件参数
    /// </summary>
    public class MouseEventArgs : EventArgs
    {
        #region 私有变量

        private uint fwKeys;
        private int xPos;
        private int yPos;
        #endregion

        #region 公共属性

        public uint Keys
        {
            get
            {
                return fwKeys;
            }
        }
        /// <summary>
        /// 获取触发鼠标事件时的X坐标
        /// </summary>
        public int X
        {
            get
            {
                return xPos;
            }
        }
        /// <summary>
        /// 获取触发鼠标事件时的Y坐标
        /// </summary>
        public int Y
        {
            get
            {
                return yPos;
            }
        }
        #endregion

        public MouseEventArgs(uint fwKeys, int xPos, int yPos)
        {
            this.fwKeys = fwKeys;
            this.xPos = xPos;
            this.yPos = yPos;
        }
    }
    /// <summary>
    /// 控件获得焦点事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    public delegate void FocusedEventHandler(object sender, FocusedEventArgs e);
    /// <summary>
    /// Focused事件参数
    /// </summary>
    public class FocusedEventArgs : EventArgs
    {
        /// <summary>
        /// 获取控件在获得焦点之前含有焦点的控件
        /// </summary>
        public Control PrevControl
        {
            get;
            private set;
        }
        /// <summary>
        /// 构造Focused事件参数
        /// </summary>
        /// <param name="prevControl">控件在获得焦点之前含有焦点的控件</param>
        public FocusedEventArgs(Control prevControl)
        {
            PrevControl = prevControl;
        }
    }
    /// <summary>
    /// 当控件失去焦点后触发此事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    public delegate void LostFocusEventHandler(object sender, LostFocusEventArgs e);
    /// <summary>
    /// LostFocus事件参数
    /// </summary>
    public class LostFocusEventArgs : EventArgs
    {
        /// <summary>
        /// 获取控件失去焦点后捕获焦点的控件
        /// </summary>
        public Control NextControl
        {
            get;
            private set;
        }
        /// <summary>
        /// 构造Focused事件参数
        /// </summary>
        /// <param name="prevControl">控件失去焦点后捕获焦点的控件</param>
        public LostFocusEventArgs(Control nextControl)
        {
            NextControl = nextControl;
        }
    }
    #endregion

    #region List控件事件
    /// <summary>
    /// 当List控件绘制列表项时触发此事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    public delegate void DrawItemEventHandler(object sender, DrawItemEventArgs e);
    /// <summary>
    /// 列表项被选中后触发此事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    public delegate void ItemSelectedEventHandler(object sender, ItemSelectedEventArgs e);
    /// <summary>
    /// DrawItem事件参数
    /// </summary>
    public class DrawItemEventArgs : EventArgs
    {
        #region 私有变量
        private Graphics g;
        private int itemIndex;
        private Rectangle rectItem;
        private Rectangle rectList;
        private Rectangle rectUpdate;
        private bool drawDefault;
        #endregion

        #region 公共属性
        /// <summary>
        /// 获取绘图面
        /// </summary>
        public Graphics Graphics
        {
            get
            {
                return this.g;
            }
        }
        /// <summary>
        /// 获取要绘制的列表项的索引
        /// </summary>
        public int ItemIndex
        {
            get
            {
                return itemIndex;
            }
        }
        /// <summary>
        /// 获取要进行绘制的列表项所在区域
        /// </summary>
        public Rectangle ItemRectangle
        {
            get
            {
                return rectItem;
            }
        }
        /// <summary>
        /// 获取引发此事件的列表控件所在区域
        /// </summary>
        public Rectangle ListRectangle
        {
            get
            {
                return rectList;
            }
        }
        /// <summary>
        /// 获取要更新的矩形区域
        /// </summary>
        public Rectangle UpdateRectangle
        {
            get
            {
                return rectUpdate;
            }
        }
        /// <summary>
        /// 获取或设置一个值，指示是否由系统来绘制此列表项
        /// </summary>
        public bool DrawDefault
        {
            get
            {
                return this.drawDefault;
            }
            set
            {
                if (value != this.drawDefault)
                {
                    this.drawDefault = value;
                }
            }
        }
        #endregion

        #region 构造函数
        /// <summary>
        /// 构造DrawItemEventArgs
        /// </summary>
        /// <param name="g">绘图面</param>
        /// <param name="itemIndex">要绘制的列表项的索引</param>
        /// <param name="rectItem">要进行绘制的列表项所在区域</param>
        /// <param name="rectList">列表控件所在区域</param>
        /// <param name="rectUpdate">要更新的矩形区域</param>
        public DrawItemEventArgs(Graphics g, int itemIndex, Rectangle rectItem, Rectangle rectList, Rectangle rectUpdate)
        {
            this.g = g;
            this.itemIndex = itemIndex;
            this.rectItem = rectItem;
            this.rectList = rectList;
            this.rectUpdate = rectUpdate;
        }
        #endregion

        #region 函数
        /// <summary>
        /// 绘制列表项被选中后的背景
        /// </summary>
        public void DrawItemSelectedBackground()
        {
            if (Graphics == null)
                return;

            bool result = MzGraphicsAPI.DrawSelectedBackground(Graphics, ItemRectangle);
        }
        /// <summary>
        /// 判断是否需要重绘列表项
        /// </summary>
        /// <returns>返回true，表示需要重绘；否则无需重绘</returns>
        public bool NeedRedrawItem()
        {
            if (UpdateRectangle.IntersectsWith(ItemRectangle))
                return true;
            return false;
        }
        #endregion
    }
    /// <summary>
    /// ItemSelected事件参数
    /// </summary>
    public class ItemSelectedEventArgs : EventArgs
    {
        private ListControlBase owner;
        private int itemIndex;
        //private uint fwKeys;

        private int xPos;
        private int yPos;

        #region 公共属性
        /// <summary>
        /// 获取被选中的列表项的索引
        /// </summary>
        public int ItemIndex
        {
            get
            {
                return this.itemIndex;
            }
        }
        /// <summary>
        /// 获取被选中的列表项
        /// </summary>
        public ListItem Item
        {
            get
            {
                if (owner == null)
                    return null;
                return owner.Items[itemIndex];
            }
        }
        /// <summary>
        /// 获取触点X坐标
        /// </summary>
        public int X
        {
            get
            {
                return xPos;
            }
        }
        /// <summary>
        /// 获取触点Y坐标
        /// </summary>
        public int Y
        {
            get
            {
                return yPos;
            }
        }
        #endregion

        /// <summary>
        /// 构造ItemSelectedEventArgs
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="itemIndex"></param>
        /// <param name="xPos"></param>
        /// <param name="yPos"></param>
        public ItemSelectedEventArgs(ListControlBase owner, int itemIndex, int xPos, int yPos)
        {
            if (owner == null)
            {
                throw new ArgumentNullException("owner");
            }
            this.owner = owner;
            this.itemIndex = itemIndex;
            this.xPos = xPos;
            this.yPos = yPos;
        }
    }

    /// <summary>
    /// 列表单击事件参数
    /// </summary>
    public class ListBoxClickEventArgs : EventArgs
    {
        public ListBoxClickEventArgs(int index)
        {
            Index = index;
        }
        /// <summary>
        /// 获取用户点击的列表项索引
        /// </summary>
        public int Index
        {
            get;
            private set;
        }
    }
    #endregion

    #region 工具条控件事件
    /// <summary>
    /// 当用户单击工具条上按钮时触发此事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    public delegate void IconToolBarButtonClickedEventHandler(object sender, IconToolBarButtonClickedEventArgs e);
    /// <summary>
    /// IconToolBarButtonClicked 事件参数
    /// </summary>
    public class IconToolBarButtonClickedEventArgs : EventArgs
    {
        public int Index
        {
            get;
            private set;
        }
        /// <summary>
        /// 构建图标工具条单击事件
        /// </summary>
        /// <param name="index"></param>
        public IconToolBarButtonClickedEventArgs(int index)
        {
            Index = index;
        }
    }
    #endregion
}
